<?
require_once("../config/dbconn.php");require_once("../config/usercls.php");require_once("../config/pagecls.php");
if($action=='del'){
	$db->delete("{$db_prefix}orders","id='$id'");
	$db->delete("{$db_prefix}orders1","orderid='$id'");
	echo "<script>location.href='order_lst0.php?pageno={$pageno}';</script>";exit();
}
if($action=='pay'){
	$msg='';
	$sql="select * from {$db_prefix}orders where id='$id'";
	$rs=$db->get_one($sql);
	if ($rs['state']!=0) $msg.="订单支付状态错误\\n";
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
  $price = $rs['gcprice']/$glo_dpjrate_1/$glo_dpjmax_2; //计算需要的英伦币个数
  $gwprice = $price*$glo_dpjmax_3/100;  //购物币
  $jjprice = $price-$gwprice;           //奖金币
//	$gwprice=$rs['gcprice'];//*$rs['zhekou']/10;
	$bdid = $rs['id'];
	//是否有足够的购物币
	$sqlhy="select * from {$db_prefix}users where id='".$_SESSION['sys_userid']."'";
	$rshy=$db->get_one($sqlhy);
	
	if ($rshy['gwprice']<$gwprice && $gwprice>0) $msg.="您没有足够的购物币\\n";
  if ($rshy['jjprice']<$jjprice && $jjprice>0) $msg.="您没有足够的奖金币\\n";
	//$abccc = $rshy['gcprice'];
/*	echo "<script>alert('$abccc');</script>";
	echo "<script>alert('$gcprice');</script>";*/
	//if ($rshy['gcprice']<$gcprice && $gcprice >0) $msg.="您没有足够的积分\\n";
	if ($msg!=''){
		echo "<script>alert('$msg');history.back();</script>";exit();
	}
	$username0=$rshy['username'];

  //扣除购物币，奖金币
  unset($dataArray);
  $dataArray['gwprice']=$rshy['gwprice']-$gwprice;
  $dataArray['jjprice']=$rshy['jjprice']-$jjprice;
  $condition="id='".$_SESSION['sys_userid']."'";
  $dataArray['username']=$_SESSION['sys_username'];
  $db->update("{$db_prefix}users",$dataArray,$condition);

	//财务记录
	
	$e_userid=$_SESSION['sys_userid'];$e_price=-$gwprice;$e_type=29;$e_ptype=5;$e_addtime=$curtime;$e_memo=$_SESSION['sys_username']."购物，购物币支付订单，单号".$rs["id"];
	hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);

  $e_userid=$_SESSION['sys_userid'];$e_price=-$jjprice;$e_type=29;$e_ptype=3;$e_addtime=$curtime;$e_memo=$_SESSION['sys_username']."购物，奖金币支付订单，单号".$rs["id"];
  hyepricejl($e_userid,$e_price,$e_type,$e_ptype,$e_addtime,$e_memo);
//更新订单的状态
	$sqlgx="update {$db_prefix}orders set state=1,zftime='$curtime' where id='".$id."'";
	$db->query($sqlgx);
	
	//支付成功
	//require("../enterc.php");
	echo"<script>alert('支付成功');</script>";
	echo "<script>location.href='order_lst0.php?pageno={$pageno}';</script>";exit();
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	
}
td{
font-size:12px;
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td width="935" height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">未支付订单</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td height="13" valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                <tr>
                  <td class="left_bt2">&nbsp;</td>
                </tr>
              </table></td>
            </tr>
            <tr>
              <td height="30"><table width="100%" height="60" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="30" align="center" bgcolor="#f2f2f2" >订单编号</td>
                  <td align="center" bgcolor="#f2f2f2" >市场价</td>
                  <td align="center" bgcolor="#f2f2f2" >会员价</td>
                  <td align="center" bgcolor="#f2f2f2" >爱华购物币</td>
                  <td align="center" bgcolor="#f2f2f2" >英伦币</td>
                  <td align="center" bgcolor="#f2f2f2" >状态</td>
                  <td align="center" bgcolor="#f2f2f2" >订单时间</td>
                  <td height="30" align="center" bgcolor="#f2f2f2" >操作</td>
                  </tr>
  <?
  $query='';
  if ($action=='query'){
  	
  }
  $sql="select count(id) as c  from {$db_prefix}orders where state=0 and username='".$_SESSION['sys_username']."'";
  if ($query!='') $sql.=$query;
  $rs=$db->get_one($sql);
  $page=new pagecls(20,intval($rs['c']));
  $sql="select * from {$db_prefix}orders where state=0 and username='".$_SESSION['sys_username']."'";
  if ($query!='') $sql.=$query;
  $sql.=" order by id desc limit {$page->pastnum},{$page->pagesize}";
  $result=$db->query($sql);
  while($rs=$db->fetch_array($result)){
  ?>
                <tr>
                  <td align="center"><?=$rs['id']?></td>				  	
                  <td align="center"><?=$rs['scprice']?> </td>
                  <td align="center"><?=$rs['gcprice']?> </td>
                  <td align="center"><?=$rs['price']?></td>
                  <td align="center"><?=$rs['pv']?></td>
                  <td align="center" class="left_ts"><? if($rs['state']==0) echo "未支付";elseif($rs['state']==1) echo "已支付";elseif($rs['state']==2) echo "已发货";elseif($rs['state']==3) echo "已收货";?></td>
                  <td align="center" ><?=date("Y-m-d H:i:s",$rs['addtime'])?></td>
                  <td height="30" align="center" ><a href="order_view.php?id=<?=$rs['id']?>&pageno=<?=$page->pageno?>">查看</a>|<a href="?action=pay&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>">支付</a>|<a href="?action=del&id=<?=$rs['id']?>&pageno=<?=$page->pageno?>">删除</a></td>
                  </tr>
	<?
  }
  $db->free_result($result);
  ?>
              </table></td>
            </tr>
            
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
            <tr>
              <td height="30" align="right">每页<?=$page->pagesize?>条 第<?=$page->pageno?>/<?=$page->pagenum?>页 共<?=$page->recnum?>条 <a href='?<?=$page->url?>1'><img src="image1/first.gif" border="0"></a>   <a href='?<?=$page->url.($page->pageno-1)?>'><img src="image1/back.gif" border="0"></a>  <a href='?<?=$page->url.($page->pageno+1)?>'><img src="image1/next.gif" border="0"></a>   <a href='?<?=$page->url.$page->pagenum?>'><img src="image1/last.gif" border="0"></a></td>
              </tr>
            <tr>
              <td height="30">&nbsp;</td>
            </tr>
          </table></td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>
